package com.meepo.feed.history

import android.os.Bundle
import android.view.View
import com.meepo.basic.components.listfragment.ListFragmentParams
import com.meepo.basic.router.RouterManager
import com.meepo.basic.schema.Enums
import com.meepo.basic.components.view.MeepoActivity
import com.meepo.feed.R
import com.meepo.framework.design.helper.StatusBarHelper
import com.meepo.framework.design.tabs.ViewPagerHelper
import com.meepo.framework.design.tabs.buildins.commonnavigator.CommonNavigator
import com.meepo.framework.design.tabs.sample.TextTab
import com.meepo.framework.design.tabs.sample.navadapters.ColorTransitionNavigatorAdapter
import com.meepo.framework.design.viewpager.adapter.DefaultFragmentStatePagerAdapter
import com.xiaojinzi.component.anno.RouterAnno
import com.xiaojinzi.component.support.ParameterSupport
import kotlinx.android.synthetic.main.history_activity.*
import kotlinx.android.synthetic.main.history_activity.magic_indicator
import kotlinx.android.synthetic.main.history_activity.view_pager

@RouterAnno(hostAndPath = RouterManager.FeedModule.FeedHistory_Path)
class HistoryActivity : MeepoActivity() {

    override fun initView(view: View, savedInstanceState: Bundle?) {

        StatusBarHelper.immerse(this, header_rl)
        back_iv.setOnClickListener { finish() }

        val index = ParameterSupport.getInt(intent, "index") ?: 0

        val tabs = listOf("帖子", "评论", "分享", "顶过", "历史").map {
            TextTab(
                it, it,
                selectedTextColor = resources.getColor(R.color.primary_color),
                unSelectedTextColor = resources.getColor(R.color.primary_text_color)
            )
        }.toList()


        val listFragmentParams = ListFragmentParams(enablePullRefresh = false)

        val mFragments = listOf(
            HistoryListFragment.instance(action = Enums.ACTION_TYPE_PUBLISHED, listFragmentParams = listFragmentParams),
            HistoryListFragment.instance(action = Enums.ACTION_TYPE_COMMENTED, listFragmentParams = listFragmentParams),
            HistoryListFragment.instance(action = Enums.ACTION_TYPE_SHARED, listFragmentParams = listFragmentParams),
            HistoryListFragment.instance(action = Enums.ACTION_TYPE_ATTITUDE, listFragmentParams = listFragmentParams),
            HistoryListFragment.instance(action = Enums.ACTION_TYPE_READ, listFragmentParams = listFragmentParams)
        )

        val commonNavigator =
            CommonNavigator(this, ColorTransitionNavigatorAdapter(tabs) { index -> view_pager.currentItem = index })
        magic_indicator.navigator = commonNavigator

        view_pager.adapter = DefaultFragmentStatePagerAdapter(supportFragmentManager, mFragments)

        ViewPagerHelper.bind(magic_indicator, view_pager)

        view_pager.currentItem = index
    }

    override fun setUpContentLayout(): Int = R.layout.history_activity

    override fun initData() {
    }

}